package signGrammar.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;

import signGrammar.IShape;

public class CShapePrinter {
	private static final int   OVAL_RADIUS = 3;	
	private static final Color NAME_COLOR = Color.BLACK;
	
	private static final Color TAIL_COLOR = Color.BLUE;
	private static final Color HEAD_COLOR = Color.BLACK;
	
	private static void printOval(Graphics g, Point sPoint, Color c){
		g.setColor( c );
		g.fillOval(sPoint.x-OVAL_RADIUS, sPoint.y-OVAL_RADIUS, OVAL_RADIUS*2, OVAL_RADIUS*2);
	}
	
	public static void printShapeName( Graphics g, String name ){
		g.setColor(NAME_COLOR);
		g.setFont( new Font("", Font.BOLD, 14) );
		g.drawString(name, 5, 15);
	} 
	
	public static void printTail(Graphics g, IShape s, Color c){
		printOval(g, s.getTail(), c);
	}
	
	public static void printHead(Graphics g, IShape s, Color c){
		printOval(g, s.getHead(), c);
	}
	
	public static void printTail(Graphics g, IShape s){
		printTail(g, s, TAIL_COLOR);
	}
	
	public static void printHead(Graphics g, IShape s){
		printHead(g, s, HEAD_COLOR);
	}
	
	public static void print(Graphics g, IShape... shapes){
		for( IShape s: shapes )
			s.print( g );
	}
	
	public static void printWithHeadsAndTails(Graphics g, IShape... shapes){
		for( IShape s: shapes ){
			printHead(g, s);
			s.print( g );
			printTail(g, s);
		}
	}
	
	private final Graphics graphics;
	public CShapePrinter(Graphics g) {
		graphics = g;
	}
	
	public CShapePrinter printTail(IShape s, Color c){
		printOval(graphics, s.getTail(), c);
		return this;
	}
	
	public CShapePrinter printHead( IShape s, Color c){
		printOval(graphics, s.getHead(), c);
		return this;
	}
	
	public CShapePrinter printTail(IShape s){
		printTail(graphics, s, TAIL_COLOR);
		return this;
	}
	
	public CShapePrinter printHead(IShape s){
		printHead(graphics, s, HEAD_COLOR);
		return this;
	}
	
	private boolean printHeadAndTails = false;
	public CShapePrinter setPrintingHeadAndTails(boolean b){
		printHeadAndTails = b;
		return this;
	}
	public CShapePrinter print(IShape... shapes){
		if ( printHeadAndTails )
			printWithHeadsAndTails(shapes);
		else
			print(graphics, shapes);
		return this;
	}
	
	public CShapePrinter printWithHeadsAndTails(IShape... shapes){
		for( IShape s: shapes ){
			print(graphics, s);
			printHead(s).printTail(s);
		}
		return this;
	}
}
